<?php
namespace App\Api\Controllers\Pay;
use App\Api\Bases\CommonController;
use App\Api\Services\JsonService;
use EasyWeChat\Factory;
use Illuminate\Http\Request;



class  Wxcpay extends CommonController
{

    /**
     * 微信支付
     * @return \EasyWeChat\Payment\Application
     */
    public function wxPay($body,$order_number,$total_fee)
    {
        include 'phpqrcode.php';

        if(empty($order_number)  || empty($total_fee) ){
            return JsonService::fail('参数不全','',config('code.HTTP_FAIL'));
        }

        $config = $this->pay['wechatPay'];
        $app = Factory::payment($config);
        $result = $app->order->unify([
            'body' => $body,
            'out_trade_no' =>$order_number,//订单号,
            'total_fee' =>$total_fee,//
            'notify_url' => config('pay.wechatPay.notify_url'),//异步回调
            // 支付结果通知网址，如果不设置则会使用配置里的默认地址
            'trade_type' => 'NATIVE', // 请对应换成你的支付方式对应的值类型
        ]);
        $value =$result['code_url']; //二维码内容
        $errorCorrectionLevel = 'L';//容错级别
        $matrixPointSize = config('qrcode.matrixPointSize');//生成图片大小
        //生成二维码图片
        $naem = rand(1111,9999).".jpg";
        \QRcode::png($value, $naem, $errorCorrectionLevel, $matrixPointSize, 2);
        $naem = '/'.$naem;
        echo "<img src=$naem alt=''>";
    }




}

